<? include block('htmla') ?>

<? startScript('jquery, jquery.tools'); ?><script type="text/javascript">
jQuery(function($) {
	$("input[name='create_object']").click(function() {
		var name = trim($("input[name='title']").val()), value = trim($("input[name='text']").val()), table = $("#properties");
		if (!name) { alert('Can\'t add unnamed property');	return false; }
		if (!value) { alert('Property value is empty');	return false; }
		if (table.find("td:contains('" + name + "')").length) { alert('A property with this name already exists'); return false; }
		
		table.find("tbody").append("<td>" + name + "</td><td><input type=\"text\" class=\"xwide\" name=\"meta[" + name + "]\" value=\"" + value + "\" /></td>");
		
		$("input[name='title']").val("");
		$("input[name='text']").val("")
		return false;
	});
	
	$("ul.jt-tabs").tabs("div.jt-panes > div");
});
</script><? endScript(); ?>

<div>

<form action="" method="post">

<? if (sizeof($DIAGS)) { ?>
	<div class="diags"><p><?=implode("</p><p>", $DIAGS)?></p></div>
<? } ?>


<ul class="jt-tabs"><?

	foreach($DATA['langs'] as $lang) {
		?><li><a href="#<?=$lang['text']?>"><?=$lang['assoc']?></a></li><? 
	} 
	
?></ul>

<div class="jt-panes">

	<? $t = true; 
		foreach($DATA['langs'] as $lang) { $l = $lang['text'];

		?><div class="jt-pane" style="<?=$t ? "display:block" : ""?>">


			<div><strong>Page name</strong><br />
				<input type="text" class="wide" name="name[<?=$l?>]" value="<?=dat('current', 'data', $l, 'value')?>" />
			</div>


		</div><? 
	
	$t = false; } ?>

</div>


<? if (!(dat('current', 'tag') & PT_LOCKED)) { ?>

	<fieldset>
		<legend> Keyword </legend>
		<div>(Alphanumeric characters and underscore are allowed)<br />
			<input type="text" class="wide" name="keyword" value="<?=dat('current', 'keyword')?>" />
		</div>
	</fieldset>

<? } ?>

	<fieldset>
		<legend> Page attributes </legend>
		<div>Content type
			<label><input type="radio" name="ctype" value="0" <?=(dat('current', 'kind') & PK_XML) ? '' : 'checked="checked"'?> />HTML</label>
			<label><input type="radio" name="ctype" value="<?=PK_XML?>" <?=(dat('current', 'kind') & PK_XML) ? 'checked="checked"' : ''?> />XML</label>
		</div>
		<div>Custom filter
			<? $f = 1 << PTC_SHIFT;
				for ($i = 1; $i <= PTC_NUM; $i++) {
					?><label><input type="checkbox" name="custom[]" value="<?=$i?>" <?=(dat('current', 'tag') & $f) ? 'checked' : ''?> /><?=$i?></label><?
					$f <<= 1;
				}
			?>
		</div>
	</fieldset>

	<fieldset>
		<legend> Page permissions </legend><?
		
		if (sizeof($d = dat('objs'))) { $r = dat('roles');
			?><table><?
			foreach($d as $id => $v) {
				?><tr><td><?=$v['name']?></td><td><?
				
					foreach($r as $rid => $rv) {
						?><label><input type="checkbox" name="perm[]" value="<?="$id:$rid"?>" <?=in_array($rid, (array)$v['data']) ? 'checked' : ''?> /><?=$rv['name']?></label><?
					}
				
				?></td></tr><?
			}
			?></table><?
		} else {
			?>No permissions available<?
		}
		
	?></fieldset>	

	<fieldset>
		<legend> Page template </legend><?

		if (sizeof($d = dat('templates'))) { 
		
			?><select name="tpl"><?
		
			foreach($d as $id => $v) {
				?><option value="<?=$id?>" <?=($id == dat('current', 'template')) ? 'selected' : ''?>><?="$v[name]"?></option><?
			}
			?></select><?
			
		} else {
			?>No templates available<?
		}
		
	?></fieldset>	


	<fieldset>
		<legend> Page properties </legend>
		
		<div>
		
			<? if (is_array($d = dat('current', 'meta'))) { ?>
				<table id="properties" class="xwide"><thead><tr><td>Name</td><td class="xwide">Value</td></tr></thead><tbody>
					<? foreach(dat('current', 'meta') as $id => $v) { ?>
						<tr><td><?=$id?></td><td>
							<input type="text" class="xwide" name="meta[<?=$id?>]" value="<?=$v?>" />
						</td></tr>
					<? } ?>
				</tbody></table>
			<? } ?>
	
			<h3>Add property</h3>
			<label>Name
				<input type="text" name="title" /></label>
			<label>Value
				<input type="text" name="text" /></label>
			<input type="submit" name="create_object" value="Add" />

		</div>
		
	</fieldset>

	
	<p><input type="submit" name="editor_save" value="Save" />
		<? if (!($DATA['current']['attr'] & AA_VISIBLE)) { ?><input type="submit" name="editor_save_enable" value="Save and Enable" /><? } ?>
	</p>

</form>

</div>

<? include block('_htmla');